﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Security.Permissions;
using System.Text;

namespace MedReg.Classes
{
    [Serializable]
    public class SertificateEducation : ISerializable
    {
        private EducationInstitution issueOrgField;

        private System.Nullable<System.DateTime> issueDateField;

        private string sertificateSerieField;

        private string sertificateNumberField;

        private SertificateSpeciality educationSpecialityField;

        private Employee employeeFiend;

        private static readonly SertificateEducation theOneObject = new SertificateEducation();

        public static SertificateEducation GetSertificateEducation()
        {
            return theOneObject;
        }
        /// <remarks/>
        public EducationInstitution IssueOrg
        {
            get
            {
                return this.issueOrgField;
            }
            set
            {
                this.issueOrgField = value;
            }
        }

        /// <remarks/>
        [System.Xml.Serialization.XmlElementAttribute(IsNullable = true)]
        public System.Nullable<System.DateTime> IssueDate
        {
            get
            {
                return this.issueDateField;
            }
            set
            {
                this.issueDateField = value;
            }
        }

        /// <remarks/>
        public string SertificateSerie
        {
            get
            {
                return this.sertificateSerieField;
            }
            set
            {
                this.sertificateSerieField = value;
            }
        }

        /// <remarks/>
        public string SertificateNumber
        {
            get
            {
                return this.sertificateNumberField;
            }
            set
            {
                this.sertificateNumberField = value;
            }
        }

        /// <remarks/>
        public SertificateSpeciality EducationSpeciality
        {
            get
            {
                return this.educationSpecialityField;
            }
            set
            {
                this.educationSpecialityField = value;
            }
        }
        public Employee Employee
        {
            get
            {
                return employeeFiend;
            }
            set
            {
                employeeFiend = value;
            }
        }

        [SecurityPermissionAttribute(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.SerializationFormatter)]
        public void GetObjectData(SerializationInfo info, StreamingContext context)
        {
            //throw new NotImplementedException();
            info.AddValue("IssueOrg", issueOrgField);
            info.AddValue("IssueDate", issueDateField);
            info.AddValue("SertificateSerie", sertificateSerieField);
            info.AddValue("SertificateNumber", sertificateNumberField);
            info.AddValue("EducationSpeciality", educationSpecialityField);
        }
        public SertificateEducation()
        {
        }
        public List<Classes.SertificateEducation> getSertificateEducationList(Classes.ArrayOfEmployee sEmployee)
        {

            foreach (var emp in sEmployee)
            {
                foreach (var sertificateEducation in emp.EmployeeSertificateEducation)
                {
                    sertificateEducation.Employee = emp;
                }
            }

            //var awd = sEmployee
            //    .SelectMany(award => award.EmployeeAwards, (Employees, Awards) => new { Employees, Awards })
            //    .Select(AwardsEx => new { Employee = AwardsEx.Employees, AwardsEx.Awards }).ToList();

            var cr = sEmployee.SelectMany(em => em.EmployeeSertificateEducation).ToList();

            return cr;
        }
    }
}
